package com.oly.cms.general.service.taglib;

import java.util.List;

import com.oly.cms.common.domain.entity.CmsCategory;
import com.oly.cms.common.enums.CategoryNodeTypeEnums;
import com.oly.cms.general.service.cache.GeneralCategoryCacheService;
import com.oly.cms.query.model.param.CategorySearchParam;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 分类标签
 */
@Service("categoryTag")
public class CategoryTag {

    @Autowired
    private GeneralCategoryCacheService categoryCacheService;

    /**
     * 获取分类
     * 
     * @param categoryId
     * @return
     */
    public CmsCategory selectCmsCategoryById(Long categoryId, String themeName) {
        return categoryCacheService.selectCmsCategoryById(categoryId, themeName);
    }

    /**
     * 
     * @param nodeType  类型
     * @param themeName 主题名字
     * @return
     */
    public List<CmsCategory> listCmsCategory(CategoryNodeTypeEnums nodeType,
            String themeName) {
        return categoryCacheService.listCmsCategory(null, nodeType, null, themeName);
    }

    /**
     * 
     * @param orderNum  排序
     * @param nodeType  类型
     * @param themeName 主题名字
     * @return
     */
    public List<CmsCategory> listCmsCategoryByOrder(CategoryNodeTypeEnums nodeType,
            String themeName, Long orderNum) {
        return categoryCacheService.listCmsCategory(orderNum, nodeType, null, themeName);
    }

    /**
     * 
     * @param nodeType   标签类型
     * @param categoryId 标签Id
     * 
     * @param themeName  主题名字
     * @return
     */
    public List<CmsCategory> listCmsCategory(CategoryNodeTypeEnums nodeType, Long categoryId, String themeName) {

        return categoryCacheService.listCmsCategory(null, nodeType, categoryId, themeName);
    }

    /**
     * 获取分类树
     * 
     * @param orderNum
     * @param nodeType
     * @param categoryId
     * @param themeName
     * @return
     */
    public CmsCategory selectCmsCategoryTree(Long orderNum, CategoryNodeTypeEnums nodeType, Long categoryId,
            String themeName) {
        return categoryCacheService.selectCmsCategoryTree(orderNum, nodeType, categoryId, themeName);
    }

    /**
     * 获取分类树
     * 
     * @param orderNum
     * @param nodeType
     * @param categoryId
     * @param themeName
     * @return
     */
    public CmsCategory selectCmsCategoryTree(CategoryNodeTypeEnums nodeType, Long categoryId,
            String themeName) {
        return categoryCacheService.selectCmsCategoryTree(null, nodeType, categoryId, themeName);
    }

    /**
     * 儿子节点
     * 
     * @param categoryId
     * @param themeName  主题名字
     * @return
     */
    public List<CmsCategory> listCategoryByParentId(long parentId, CategoryNodeTypeEnums nodeType, String themeName) {
        return categoryCacheService.listCmsCategory(null, nodeType, parentId, themeName);
    }

    /**
     * 
     * @param nodeType   类型
     * @param categoryId 分类Id
     * @return
     */
    public List<CmsCategory> listCategoryByType(String themeName, CategoryNodeTypeEnums nodeType, Long categoryId) {
        return categoryCacheService.listCmsCategory(null, nodeType, categoryId, themeName);
    }

    /**
     * 
     * @param orderNum   排序
     * @param categoryId 分类Id
     * @param themeName  主题名字
     * @return
     */
    public List<CmsCategory> listCategoryByOrderNum(String themeName, Long orderNum, long categoryId) {
        return categoryCacheService.listCmsCategory(orderNum, CategoryNodeTypeEnums.CLASSIFY, categoryId, themeName);
    }

    /**
     * 获取数量
     * 
     * @param themeName
     * @return
     */
    public int selectCategoryNum(String themeName, CategoryNodeTypeEnums nodeTypeEnums) {
        return categoryCacheService.selectCategoryNum(themeName, nodeTypeEnums);
    }

    public boolean checkSupportCategory(String themeName, long categoryId) {
        return categoryCacheService.checkSupportCategory(themeName, categoryId);

    }

    public List<CmsCategory> listCmsCategory(CategorySearchParam param) {

        return categoryCacheService.listCmsCategory(param);
    }

    public CmsCategory getCategoryTree(CategorySearchParam param) {

        return categoryCacheService.selectCmsCategoryTree(param);
    }

}
